//
//  QuanziTabBarController.m
//  YiqiMobile
//
//  Created by henry on 13-4-17.
//  Copyright (c) 2013年 henry. All rights reserved.
//

#import "QuanziTabBarController.h"
#import "BowenmanageViewController.h"
#import "CustomNavigationController.h"
#import "MembermanageViewController.h"
#import "QzsettingViewController.h"
#import "NotificationViewController.h"


@implementation QuanziTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
	[self hideExistingTabBar];
    NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"QuanziTabBarView" owner:self options:nil];
    self.quanziTabBarView = [nibObjects objectAtIndex:0];
	self.quanziTabBarView.homeButton.selected = YES;
    self.quanziTabBarView.delegate = self;
    self.quanziTabBarView.frame = self.tabBar.frame;
    [self.view addSubview:self.quanziTabBarView];
    NSMutableArray* array = [NSMutableArray arrayWithObjects:
                             [self createViewControllerWithClass:[BowenmanageViewController class] andXibName:nil],
                             [self createViewControllerWithClass:[MembermanageViewController class]  andXibName:nil],
                             [self createViewControllerWithClass:[QzsettingViewController class]  andXibName:nil],
                             [self createViewControllerWithClass:[NotificationViewController class]  andXibName:nil],
							 nil];
	self.viewControllers = array;
}
- (UIViewController *)createViewControllerWithClass:(Class)classname andXibName:(NSString*)xibName{
	UIViewController* viewController = [[classname alloc] initWithNibName:xibName bundle:nil];
	CustomNavigationController *navigationBarController = [[CustomNavigationController alloc] initWithRootViewController:viewController];
	
	return navigationBarController;
}

/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations.
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

// 在iOS6下已废弃
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return interfaceOrientation==UIInterfaceOrientationPortrait;
}


// Only on iOS6
- (BOOL)shouldAutorotate
{
    return NO;
}
// Only on iOS6
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}




- (void)dealloc {
    
}

- (void)hideExistingTabBar {
	for(UIView *view in self.view.subviews) {
		if([view isKindOfClass:[UITabBar class]]) {
            view.superview.backgroundColor=[UIColor whiteColor];
			view.hidden = YES;
			break;
		}
	}
}

#pragma mark -
#pragma mark TabBarDelegate
-(void)tabWasSelected:(NSInteger)index {
    self.selectedIndex = index;
}

@end
